﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Top.Api.Request;
using Top.Api.Response;
using ALS.Component.Tools.Helpers;
using ALS.Communication.Contract;

namespace ALS.Communication.Domain.Factories
{
    /// <summary>
    /// Als订单工厂
    /// </summary>
    public class AlsOrderFactory : Factory
    {
        public AlsOrderFactory() : base() { }

        public void CreateAlsOrders(List<TaobaoOrderDTO> tids)
        {
            var tidsStr = new List<string>();
            tids.ForEach(t => { tidsStr.Add(t.ToString()); });
            var topatsTradesFullinfoGetRequest = new TopatsTradesFullinfoGetRequest()
            {
                Fields = "seller_nick, buyer_nick, title, type, created, tid, seller_rate,buyer_flag, buyer_rate, status, payment, adjust_fee, post_fee, total_fee, pay_time, end_time, modified, consign_time, buyer_obtain_point_fee, point_fee, real_point_fee, received_payment, commission_fee, buyer_memo, seller_memo, alipay_no,alipay_id,buyer_message, pic_path, num_iid, num, price, buyer_alipay_no, receiver_name, receiver_state, receiver_city, receiver_district, receiver_address, receiver_zip, receiver_mobile, receiver_phone,seller_flag, seller_alipay_no, seller_mobile, seller_phone, seller_name, seller_email, available_confirm_fee, has_post_fee, timeout_action_time, snapshot_url, cod_fee, cod_status, shipping_type, trade_memo, is_3D,buyer_email,buyer_area, trade_from,is_lgtype,is_force_wlb,is_brand_sale,buyer_cod_fee,discount_fee,seller_cod_fee,express_agency_fee,invoice_name,service_orders,credit_cardfee,step_trade_status,step_paid_fee,mark_desc,has_yfx,yfx_fee,yfx_id,yfx_type,trade_source,eticket_ext,send_time,orders,promotion_details,invoice_name",
                Tids = string.Join(",", tidsStr)
            };
            var topatsTradesFullinfoGetResponse = (TopatsTradesFullinfoGetResponse)TaobaoHelper.Execute(topatsTradesFullinfoGetRequest);
            var topatsResultGetRequest = new TopatsResultGetRequest()
            {
                TaskId = topatsTradesFullinfoGetResponse.Task.TaskId
            };
            var topatsResultGetResponse = (TopatsResultGetResponse)TaobaoHelper.Execute(topatsResultGetRequest);
            //taobaoOrderDTOs.AsParallel().ForAll(o => {
            //    using (var adapter = TableAdapter<AlsOrderPoco>.Open())
            //    {
            //        var alsOrderPoco = new AlsOrderPoco()
            //        {
            //            ErpOrderID = o.ErpOrderID,
            //            TaobaoOrderID = o.TaobaoOrderID
            //        };
            //        adapter.CreateUpdate(alsOrderPoco);
            //    }
            //});
        }
    }
}
